#-*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404

from shortcuts import render_to
from models import *

@render_to('map.html')
def map(request):
    return {'rows' : Map.rows_iterator()}


@render_to('lowland.html')
def lowland(request, id):
    return {}


@render_to('settlement.html')
def settlement(request, settlement_id):
    settlement = get_object_or_404(Settlement, pk=settlement_id)
    return {
        'settlement' : settlement,
        'buildings' : BuildingSlot.objects.filter(settlement=settlement)
    }


@render_to('suburb.html')
def suburb(request, settlement_id):
    settlement = get_object_or_404(Settlement, pk=settlement_id)
    return {
        'settlement' : settlement,
        'suburb' : GroundSlot.objects.filter(settlement=settlement)
    }


@render_to('ground.html')
def ground_slot(request, settlement_id, position):
    ground = get_object_or_404(
        GroundSlot, settlement=settlement_id, position=position)
    return {'ground': ground}


def ground_slot_upgrade(request, settlement_id, position):
    ground = get_object_or_404(
        GroundSlot, settlement=settlement_id, position=position)
    # TODO add the event
    return HttpResponseRedirect(
        reverse(ground_slot, args=[settlement_id, position]))
    

@render_to('building.html')
def building_slot(request, settlement_id, position):
    return {}
